<?
ob_start(); 
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$op=$_REQUEST['op']?$_REQUEST["op"]:date("Y-m-d",strtotime("-1 month"));
$ed=$_REQUEST['ed']?$_REQUEST["ed"]:date("Y-m-d");
$oper=$opid=$list=$ids=array();
// 取得下属成员
$sel="select son_id,dname from pft_member_relationship r left join pft_member m on son_id=m.id where parent_id=".$_SESSION['sid']." and son_id_type=0 and r.status=0 and m.status=0 order by r.rectime desc";
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
	$ids[$row['son_id']]=$row['dname'];
}

$aids=array_keys($ids);// 下属成员ID
// if($aids){
	// $lmoney = array();
	// $retXml = $s->PFT_Member_Fund(implode(",",$aids), 0);
	// $object = simplexml_load_string($retXml);
	// foreach($object->Rec as $ct){
		// $fid = (string)$ct->UUfid;
		// $money = (string)$ct->UUamoney;
		// $lmoney[$fid] = $money;
		// $all+=$money;
	// }
// }
if($aids){
	$sel="select fid,group_concat(lmoney order by rectime DESC) lm from pft_member_journal where fid in (".implode(",",$aids).") and ptype=0 and rectime between '".$op." 00:00:00' and '".$ed." 23:59:59' group by fid";//echo $sel;dtype=3 and 
	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$lm=explode(",",$row['lm']);
		$lmoney[$row['fid']]=$lm[0];
		$all+=$lm[0];
	}
	$_ids=array_diff($aids,array_keys($lmoney));
	if($_ids){
		$sel="select fid,group_concat(lmoney order by rectime ASC) lm from pft_member_journal where fid in (".implode(",",$_ids).") and ptype=0 and rectime>'".$ed." 23:59:59' group by fid";//echo $sel;and dtype=3 
		$GLOBALS['le']->query($sel);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$lm=explode(",",$row['lm']);
			$lmoney[$row['fid']]=$lm[0];
			$all+=$lm[0];
		}
	}
	$_ids=array_diff($aids,array_keys($lmoney));
	foreach($_ids as $v){
		$money=simplexml_load_string($s->PFT_Member_Fund($v,0));
		$lmoney[$v]=$money->Rec[0]->UUamoney;
		$all+=$money->Rec[0]->UUamoney;
	}
}
// 导出Excel
if(isset($_REQUEST['act']) && $_REQUEST['act']=='loadExcel'){
	$Excel = array();
	$filename = $_SESSION['dname'].'成员实时账户金额-'.date('YmdHis');
	$Excel[0]['a']='成员名称';
	$Excel[0]['b']='时时账户金额';
	$i=1;
	foreach($aids as $id){
		$n++;
		$Excel[$n]['a']=$ids[$id];
		$Excel[$n]['b']=$lmoney[$id]/100;
	}
	$xls = new SimpleExcel('UTF-8', true,'实时账户金额');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}
echo $out_html;
include("tpl/lmoney.html");
include("common/footer.html");?>